package com.demo.config.ExportExcel;

import jakarta.servlet.http.HttpServletResponse;

import java.util.*;

/**
 * @class：ExportTest
 * @since: 2023/9/4 13:46
 * @description: 动态excel列表
 */
public class ExportTest {

	public static void main(String[] args) {

		// 返回多个sheet页面
		// export1();

	}

	private static void export1() {

		List<List<Map<String, Object>>> datalists = new ArrayList<>();
		for (int i = 0; i < 2; i++) {// 注意这个个数要与接口参数中sheet的个数一致
			List<Map<String, Object>> datalist = new ArrayList<>();
			for (int j = 0; j < 10; j++) {
				Map<String, Object> map = new LinkedHashMap<>();
				map.put("aaa", "hhh" + j);
				map.put("bbb", "开朗" + j);
				map.put("ccc", "kkk" + j);
				datalist.add(map);
			}
			datalists.add(datalist);
		}

		if (!datalists.isEmpty()) {
			try {
				List<String> headers = new ArrayList<>();
				headers.add("1111111");
				headers.add("2222222");
				headers.add("3333333");
				String fileName = "mydataexcel";
				// 返回流
				HttpServletResponse response = null;
				ExportExcelUtil.exportDynamicExcel(fileName, Arrays.asList("我的sheet1", "我的sheet2"), "head0000", headers,
						datalists, response, null, true);
			}
			catch (Exception e) {
				e.printStackTrace();
			}
		}

	}

}
